class Result {
  static ok(value) {
    return new OkResult(value);
  }
  static err(value) {
    return new ErrResult(value);
  }
  /** @deprecated */
  is_ok() {
    throw new Error("Method not implemented.");
  }
  isOk() {
    throw new Error("Method not implemented.");
  }
  /** @deprecated */
  is_err() {
    throw new Error("Method not implemented.");
  }
  isErr() {
    throw new Error("Method not implemented.");
  }
  unwrap() {
    throw new Error("Method not implemented.");
  }
  /** @deprecated */
  unwrap_or() {
    throw new Error("Method not implemented.");
  }
  unwrapOr() {
    throw new Error("Method not implemented.");
  }
  /** @deprecated */
  unwrap_err() {
    throw new Error("Method not implemented.");
  }
  unwrapErr() {
    throw new Error("Method not implemented.");
  }
}

class OkResult extends Result {
  #value;
  constructor(value) {
    super();
    this.#value = value;
  }
  is_ok() {
    return true;
  }
  isOk() {
    return true;
  }
  is_err() {
    return false;
  }
  isErr() {
    return false;
  }
  unwrap() {
    return this.#value;
  }
  unwrap_or(value) {
    return value;
  }
  unwrapOr(value) {
    return value;
  }
  unwrap_err() {
    throw new ReferenceError("Cannot unwrap a success as a failure");
  }
  unwrapErr() {
    throw new ReferenceError("Cannot unwrap a success as a failure");
  }
}

class ErrResult extends Result {
  #value;
  constructor(value) {
    super();
    this.#value = value;
  }
  is_ok() {
    return false;
  }
  isOk() {
    return false;
  }
  is_err() {
    return true;
  }
  isErr() {
    return true;
  }
  unwrap() {
    throw new Error("Cannot unwrap a failure");
  }
  unwrap_or(value) {
    return value;
  }
  unwrapOr(value) {
    return value;
  }
  unwrap_err() {
    return this.#value;
  }
  unwrapErr() {
    return this.#value;
  }
}

module.exports = { Result, OkResult, ErrResult };
